home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex / vdm.tex < prev    next >
Encoding:
Text File  |  1988-04-18  |  32.9 KB  |  1,081 lines

  1. %-----------------------vdm.tex---------------
  2. \documentstyle[vdm]{article}
  3.  
  4. \title{Typesetting VDM with \LaTeX}
  5. \author{Mario Wolczko\\
  6. Dept. of Computer Science\\
  7. The University\\
  8. Manchester M13 9PL\\
  9. U.K.\\
  10. \verb;miw@uk.ac.man.cs.ux;, {\tt ...!mcvax!ukc!man.cs.ux!miw}}
  11. \date{November 1986}
  12.  
  13. \newcommand{\Vdm}{{\tt vdm\/}}
  14.  
  15. \newenvironment{dangerous}{\endgraf\vspace{5pt}\bgroup\small}%
  16.               {\endgraf\egroup\vspace{5pt}}
  17.  
  18. \newlength{\righthalf} \setlength{\righthalf}{0.5\textwidth}
  19. \newlength{\lefthalf}  \setlength{\lefthalf}{0.4\textwidth}
  20. \newenvironment{leftside}{\noindent\hspace{0.1\textwidth}%
  21.               \parbox[t]{\lefthalf}\bgroup\vspace{10pt}%
  22.               \noindent\begin{vdm}\leftskip=0pt\VDMindent=0pt}%
  23.              {\end{vdm}\egroup}
  24. \newenvironment{rightside}{\parbox[t]{\righthalf}\bgroup\begin{verbatim}}%
  25.               {\egroup}
  26.  
  27. \renewcommand{\^}[1]{$\langle${\rm #1\/}$\rangle$}
  28.  
  29. \newcommand{\mmexp}{\^{math-mode-expression}}
  30. \newcommand{\cs}[1]{{\tt \string#1}}
  31.  
  32. \setlength{\VDMindent}{3\parindent}
  33.  
  34. \setlength{\preOperationSkip}{0pt}
  35. \setlength{\preFunctionSkip}{0pt}
  36. \setlength{\preTypeSkip}{0pt}
  37. \setlength{\preCompositeSkip}{0pt}
  38. \setlength{\preRecordSkip}{0pt}
  39. \setlength{\preFormulaSkip}{0pt}
  40.  
  41. \begin{document}
  42. \maketitle
  43.  
  44. This document describes a new style option, \Vdm, for use with
  45. \LaTeX.  The purpose of \Vdm\ is to make the typesetting of VDM
  46. specifications easy.  Other goals are:
  47. \begin{itemize}
  48. \item    To enable users of \Vdm\ to communicate their specifications
  49.     to others, possibly in a variety of concrete syntaxes, without
  50.     having to change their source files
  51. \item    To help the VDM community standardise on a particular form of VDM.
  52.     This, of course, is in direct contradiction to the first
  53.     aim
  54. \item    To enable a user of \Vdm\ to concentrate on his%
  55.     \footnote{Read `his/her' for every occurence of `his'.}
  56.     specifications, and ignore the detailed layout as much as
  57.     possible.  A side effect of this is that the effort required
  58.     to improve layout is concentrated in one place, within the
  59.     \Vdm\ macros.
  60. \end{itemize}
  61.  
  62. But enough evangelising.  Let's get to the the real meat.  This
  63. document is broken up into the following sections:
  64. \begin{itemize}
  65. \item    General points about using \Vdm
  66. \item    Typesetting formulas
  67. \item    How to typeset data types
  68. \item    How to typeset functions
  69. \item    How to typeset operations
  70. \item    How to typeset proofs
  71. \item    How to tailor/extend the system for your own
  72.     application.
  73. \end{itemize}
  74. You should definitely read the first two sections---then you'll know
  75. roughly what you're in for, and whether you want to continue.  The
  76. remaining sections can be read as and when you need them.
  77.  
  78. \begin{dangerous}
  79. In keeping with the best traditions of \TeX\ documentation, paragraphs
  80. that contain material that is not essential for novices, but vital if
  81. you want to parameterise or extend the system, are in smaller type,
  82. like this one.
  83. \end{dangerous}
  84.  
  85. Just to give a preliminary example, here is some output from \Vdm, and
  86. the corresponding input:
  87.  
  88. \begin{vdm}
  89. \begin{fn}{dec}{ptrs,om} \\
  90. \signature{
  91.      \setof{Oop} \x \mapof{Oop}{Object} \to \mapof{Oop}{Object} 
  92. }
  93. \If ptrs = \emptyset
  94. \Then om
  95. \Else     \Let gone = \set{p \in ptrs | RC(om(p)) = 1} \In
  96.     \Let om' = gone \dsub om \In
  97.     \Let om'' = om' \owr
  98.         \map{p \mapsto \chg{om'(p)}{RC}{RC\minus 1}\T3
  99.             | p \in ptrs \diff gone} \In
  100.     dec(\Union\set{\elems{BODY(om(p))} | p \in gone}, om'')
  101. \Fi
  102. \end{fn}
  103.  
  104. \begin{op}[DESTROYPTR]
  105. \args{ Obj, Ptr : Oop }
  106. \ext{ \Wr OM : \mapof{Oop}{Basic_Object} }
  107. \pre{ ptr \in  \elems{BODY(om(obj))} }
  108. \post{ om = ~{om} \owr \map{ obj \mapsto 
  109.         \chg{om(obj)}{BODY}{BODY \diff \set{ptr}}}}
  110. \end{op}
  111. \end{vdm}
  112.  
  113. % this is verbatim input
  114. \begin{verbatim}
  115. \begin{vdm}
  116. \begin{fn}{dec}{ptrs,om} \\
  117. \signature{
  118.       \setof{Oop} \x \mapof{Oop}{Object} \to \mapof{Oop}{Object} 
  119. }
  120. \If ptrs = \emptyset
  121. \Then om
  122. \Else   \Let gone = \set{p \in ptrs | RC(om(p)) = 1} \In
  123.         \Let om' = gone \dsub om \In
  124.         \Let om'' = om' \owr
  125.                 \map{p \mapsto \chg{om'(p)}{RC}{RC\minus 1}
  126.                         | p \in ptrs \diff gone} \In
  127.         dec(\Union\set{\elems{BODY(om(p))} | p \in gone}, om'')
  128. \Fi
  129. \end{fn}
  130.  
  131. \begin{op}[DESTROYPTR]
  132. \args{ Obj, Ptr : Oop }
  133. \ext{ \Wr OM : \mapof{Oop}{Basic_Object} }
  134. \pre{ ptr \in  \elems{BODY(om(obj))} }
  135. \post{ om = ~{om} \owr \map{ obj \mapsto 
  136.                 \chg{om(obj)}{BODY}{BODY \diff \set{ptr}}}}
  137. \end{op}
  138. \end{vdm}
  139.  
  140. \end{verbatim}
  141.  
  142. \noindent
  143. Impressed, huh?  Read on...
  144.  
  145.  
  146. \section*{Using \Vdm---General Points}
  147.  
  148. To get at \Vdm, include {\tt vdm\/} as a document style option, e.g.:
  149. \begin{verbatim}
  150.         \documentstyle[12pt,vdm]{report}
  151. \end{verbatim}
  152. \begin{dangerous}
  153. To the best of my knowledge, the use of \Vdm\ does not conflict with
  154. any of the other document styles, except when something has been
  155. redefined.   An attempt will be made to document all such redefinitions.
  156. \end{dangerous}
  157. Once \Vdm\ has been included, you can then use the {\tt vdm\/}
  158. environment.  For example,
  159. \begin{verbatim}
  160.          \begin{vdm}
  161.             ....
  162.          \end{vdm}
  163. \end{verbatim}
  164. All specification material should be placed within the {\tt vdm\/}
  165. environment.  The use of \Vdm\ only affects text within the {\tt vdm\/}
  166. environment, except for the following global changes (which are only
  167. relevant when in math or display math mode):
  168. \begin{enumerate}
  169. \item    The mathcodes of a\dots z and A\dots Z have been changed.  In
  170.     plain English, this means that when you type letters in math
  171.     mode the inter-letter spacing is different than it would bed
  172.     had you not included \Vdm\ as an option.  This is because
  173.     \LaTeX\ math mode is usually tuned for single letter
  174.     identifiers, as used by mathematicians for millenia.  However,
  175.     you and I both know that most meaningful identifiers have more
  176.     than one letter in them, so \Vdm\ provides better spacing for
  177.     them.  As an example, if you type \verb;$identifier$;, \LaTeX\
  178.     would normally print {\defaultMathcodes$identifier$}, whereas
  179.     the use of \Vdm\ will yield $identifier$.
  180.     \begin{dangerous}\indent If you really want to use the
  181.     `normal' inter-letter spacing, say \cs\defaultMathcodes.
  182.     \end{dangerous}
  183. \item    Underscore gives you an underscore, and not a subscript.  If
  184.     you want a subscript use \verb;@;, e.g.,~$x@0$ is typed
  185.     \verb;x@0;, or use \TeX's \cs\sb\ macro.  An @ is still an
  186.     @ when not in math mode.  Occasionally you may find that an @
  187.     in math mode {\em doesn't\/} give you a subscript.  Should
  188.     this happen, you are advised to use \TeX's \cs\sb macro,
  189.     e.g.,~\verb;$x\sb0$;. 
  190.     \begin{dangerous}
  191.     If you don't use
  192.     underscores much, and you want to use \verb;_; for subscripts,
  193.     you can say \cs\underscoreon\ (and \cs\underscoreoff\ to
  194.     make it revert to its usual meaning in \Vdm).
  195.     \end{dangerous}
  196.  
  197. \item    \verb;-; typesets a hyphen, and not a minus sign.  VDM specifications
  198.     usually contain a lot more
  199.     \begin{vdm}$long-identifiers$\end{vdm} than subtractions, so
  200.     on the whole this alteration should save effort.  If you really want
  201.     to do a subtraction, use \cs\minus.
  202.  
  203. \item    \verb;|; gives you a \begin{vdm}$|$\end{vdm}, and not a $\vert$.
  204.     Do you see the difference?  No?  The former goes between things,
  205.     e.g., \begin{vdm}$\set{x|p(x)}$\end{vdm}, while the latter is
  206.     a delimiter, e.g.,~$|x|$.
  207.     Most people use the former more than the latter, so again this
  208.     seems reasonable.  If you really want a $|$ (the second kind),
  209.     say \cs\vert. 
  210.  
  211. \item    In \TeX\ and \LaTeX\ \verb;~; has always been a tie.  Well
  212.     in \Vdm\ it isn't.  \verb;~x; will give you a
  213.     \begin{vdm}$~x$\end{vdm}.  For long identifiers, such as
  214.     \begin{vdm}$~{long}$\end{vdm}, say
  215.     \verb;~{long};  {\em Note that this only applies in math
  216.     mode; elsewhere a \verb;~; is still a tie.} 
  217. \item    In math mode, the double quote character \verb;"; is actually
  218.     a macro.  Placing text between pairs of double quotes causes
  219.     that text to be set in the normal text font.  For example,
  220.     \verb;$x="a variable"$; gives you $x="a variable"$.  
  221.     \begin{dangerous}
  222.     If you want to change the font used for text placed between
  223.     quotes, redefine the command \cs\mathTextFont.  By default
  224.     it is defined to be \cs\rm.
  225.     \end{dangerous}
  226. \item    The following macros have been altered in a non-trivial way:
  227.     \cs\forall, \cs\exists.
  228. \end{enumerate}
  229.  
  230. \begin{dangerous}
  231. When you typeset some VDM within the {\tt vdm\/} environment, by
  232. default it is set in from the left margin by an amount equal to
  233. \cs\parindent, the indentation at the beginning of each paragraph.
  234. If you want to change this, change the value of \cs\VDMindent, e.g.:
  235. \begin{verbatim}
  236.         \setlength{\VDMindent}{0cm}
  237. \end{verbatim}
  238. will make your specs come out flush left.  This document has been
  239. typeset with \cs\VDMindent\ equal to $3\times \cs\parindent$.
  240. \end{dangerous}
  241.  
  242. \begin{dangerous}
  243. Similarly, you can have a particular line spacing in force within the
  244. {\tt vdm} environment.
  245. %  However, you have to tread carefully here.
  246. %\TeX\ {\em always\/} enforces a single line spacing within a
  247. %particular paragraph, and the value used is the value current at the
  248. %{\em end\/} of the paragraph.  So to make the material within a {\tt
  249. %vdm} environment have a different spacing from that surrounding it,
  250. %you must always put it in a separate paragraph, by placing a blank
  251. %line before and after it, otherwise strange things will happen.  
  252. The spacing within a {\tt vdm} environment is dictated by the
  253. \cs\VDMbaselineskip\ command.  Note that this is {\em not\/} a
  254. length, but a command.  By default it expands to \cs\baselineskip\
  255. so that the line spacing is that of the surrounding text, whatever 
  256. size that may be.  To make it smaller, you may want to say
  257. \begin{verbatim}
  258.     \renewcommand{\VDMbaselineskip}{0.8\baselineskip}
  259. \end{verbatim}
  260. for example.
  261. \end{dangerous}
  262.  
  263.  
  264. \section*{Typesetting formulas}
  265.  
  266. Most of the text you enter within {\tt vdm\/} environments will be in
  267. \TeX's math mode, but VDM does its best to conceal this fact from you,
  268. so that you should rarely, if ever, have to type a dollar sign.
  269. However, several new features have been provided for the typesetting
  270. of logical formulas.  Firstly, operators with sensible names have been
  271. provided: use \cs\Iff, \cs\Implies, \cs\Or, \cs\And\
  272. and \cs\Not\ for the operators~\begin{vdm}%
  273. $\Iff,\Implies,\Or,\And,\Not$\end{vdm}.
  274. (To retain compatibility with a previous version, \cs\iff,
  275. \cs\implies, \cs\and\ and \cs\neg\ are still provided, but
  276. \cs\or\ is not.)
  277.  
  278. A major change has come in the area of quantified expressions.  They
  279. have very well-defined forms, so the \LaTeX\ sequences \cs\forall\
  280. and \cs\exists\ have been re-defined to take arguments.  For
  281. example, to get
  282. \begin{vdm}
  283. \begin{formula}
  284. \exists{x \in S}{p(x)}
  285. \end{formula}
  286. \end{vdm}
  287. \noindent type
  288. \begin{verbatim}
  289.         \exists{x \in S}{p(x)}
  290. \end{verbatim}
  291. Note the separating dot that was put in auto\-matically.  If you want
  292. one of these dots by itself, you can have one by saying
  293. \cs\suchthat.
  294.  
  295. In addition, a new quantifier, \cs\unique, has been added:
  296.  
  297. \begin{leftside}
  298. \begin{formula}
  299. \unique{x \in S}{p(x)}
  300. \end{formula}
  301. \end{leftside}\begin{rightside}
  302. \unique{x \in S}{p(x)}
  303. \end{verbatim}\end{rightside}
  304.  
  305. \begin{dangerous}
  306. If you want to use the old versions of \cs\forall\ and
  307. \cs\exists\ they are available under the pseudonyms of
  308. \cs\Forall\ and \cs\Exists.
  309. \end{dangerous}
  310.  
  311. If you find that the body of the quantified expression is too long to
  312. fit comfortably on a line, there are *-forms of the above commands
  313. that place the body of the quantified expression on a new line,
  314. slightly indented.  For example,
  315.  
  316. \begin{vdm}
  317. \begin{formula}
  318. \exists*{x \in S}{
  319.     p(x) \And q(x) \Or \Not p(x) \Implies r(x) \And S(x)}
  320. \end{formula}
  321. \end{vdm}
  322.  
  323. \noindent can be obtained with
  324. \begin{verbatim}
  325.       \exists*{x \in S}{p(x) \And q(x) \Or \Not p(x)
  326.                         \Implies r(x) \And S(x)}
  327. \end{verbatim}
  328.  
  329. If you need ``Strachey'' brackets, e.g., $M\term{e}$, place the
  330. material to appear within the brackets within \verb;\term{ ... };,
  331. thus: \verb;$M\term{e}$;.
  332.  
  333. A special control sequence, \cs\const, is available for constants.
  334. To get, for example, $\const{Yes}|\const{No}$, type
  335. \verb;\const{Yes}|\const{No};.
  336. \begin{dangerous}
  337. If you don't like the font that constants are set in, you can change
  338. them by redefining the command \cs\constantFont.  By
  339. default it expands to \cs\sc.
  340. \end{dangerous}
  341.  
  342. \subsection*{The {\tt formula} Environment}
  343.  
  344. Occasionally you may want a formula on its own, between paragraphs of
  345. text, say.  Normally, the provided environments and commands suffice,
  346. but sometimes they don't.  If you need an odd equation to stand on its
  347. own, use the {\tt formula} environment:
  348. \begin{verbatim}
  349.        \begin{formula}
  350.        x = 10
  351.        \Or  \forall{i \in \Nat}{i \ne 10 \Implies i \ne x}
  352.        \end{formula}
  353. \end{verbatim}
  354. \sloppy
  355. The {\tt formula} environment is similar to displayed math mode,
  356. except: formulas are indented by \cs\VDMindent, not
  357. \cs\mathindent, and line breaks can be made using \cs\\.
  358. Also, within the {\tt formula} environment everything appears flush
  359. left, as opposed to being centred. 
  360.  
  361.  
  362. \subsection*{Constructions}
  363.  
  364. A particularly nice feature of \Vdm\ is that you can typeset multi-line
  365. constructions such as those in the earlier example without having to
  366. worry about, say, lining up ``thens'' and ``elses'' with ``ifs''.
  367. In the following definitions, whenever you see the term \mmexp, you
  368. should type an expression as if in math mode, but you needn't put
  369. dollar signs in.  All of the constructions described below can be used
  370. where a \mmexp\ is required.  Each construction is shown by example;
  371. the output on the left results from the input on the right.
  372. Also note that each macro name begins with an upper-case letter.
  373. \TeX\ and \LaTeX\ frequently use the lower-case variants for
  374. completely unrelated things.  Naturally, chaos will ensue if you mix
  375. the names up.
  376.  
  377. Typesetting an \kw{if} is done using \cs\If\ \mmexp \cs\Then\ \mmexp
  378. \cs\Else\ \mmexp \cs\Fi.
  379.  
  380. \begin{leftside}
  381.   \begin{formula}
  382.     \If x\in S
  383.     \Then S \diff x
  384.     \Else \emptyset
  385.     \Fi
  386.   \end{formula}
  387. \end{leftside}%
  388. \begin{rightside}
  389. \If x\in S
  390. \Then S \diff x
  391. \Else \emptyset
  392. \Fi
  393. \end{verbatim}
  394. \end{rightside}
  395.  
  396. If you nest \cs\If{}s then you must enclose inner \cs\If{}s within
  397. braces:
  398.  
  399. \begin{leftside}
  400.   \begin{formula}
  401.         \If \ldots
  402.         \Then{
  403.                 \If \ldots
  404.                 \Then \ldots
  405.                 \Else \ldots
  406.                 \Fi
  407.         }\Else
  408.         \Fi
  409.   \end{formula}
  410. \end{leftside}\begin{rightside}
  411. \If ... 
  412. \Then{
  413.         \If ...
  414.         \Then ...
  415.         \Else ...
  416.         \Fi
  417. }\Else
  418. \Fi
  419. \end{verbatim}\end{rightside}
  420.  
  421. You are advised to place the extra braces exactly as above; don't let
  422. extraneous spaces intervene between the keywords and the braces.
  423.  
  424. The \cs\If\ macro always starts a new line for the \kw{then} and
  425. \kw{else} parts.  If you want \TeX\ to try to choose line breaks, use
  426. \cs\SIf\ instead:
  427.  
  428. \begin{leftside}
  429.   \begin{formula}
  430.     \SIf a=b
  431.     \Then c=d+e
  432.     \Else p=q+r+s+t+u
  433.     \Fi
  434.   \end{formula}
  435. \end{leftside}%
  436. \begin{rightside}
  437. \SIf a=b
  438. \Then c=d+e
  439. \Else p=q+r+s+t+u
  440. \Fi
  441. \end{verbatim}
  442. \end{rightside}
  443.  
  444. \mbox{\kw{let}\dots\kw{in}} constructions are done in a similar way:
  445. \cs\Let\ \mmexp \cs\In\ \mmexp, and \cs\SLet\ \mmexp
  446. \cs\In\ \mmexp. 
  447.  
  448. \begin{leftside}
  449.   \begin{formula}
  450.     \Let x=f(y,z) \In
  451.     g(x)+h(x)
  452.   \end{formula}
  453. \end{leftside}%
  454. \begin{rightside}
  455. \Let x=f(y,z) \In
  456. g(x)+h(x)
  457. \end{verbatim}
  458. \end{rightside}
  459.  
  460. \begin{leftside}
  461.   \begin{formula}
  462.     \SLet x=f(y,z) \In{
  463.       g(x)+h(x)
  464.     }
  465.   \end{formula}
  466. \end{leftside}%
  467. \begin{rightside}
  468. \SLet x=f(y,z) \In{
  469. g(x)+h(x)
  470. }
  471. \end{verbatim}
  472. \end{rightside}
  473.  
  474. Notice that \cs\SLet\ takes a second argument, which is part of the
  475. same `paragraph', where \cs\Let\ does not.
  476.  
  477. The typesetting of a \kw{cases} clause is more complicated.  It takes
  478. the form:
  479. \begin{verse}
  480. \verb;\Cases{; \mmexp \verb;}; \\
  481. from-\mmexp \verb;&; to-\mmexp \cs\\ \\
  482. from-\mmexp \verb;&; to-\mmexp \cs\\ \\
  483. \dots \\
  484. \verb;\Otherwise{; \mmexp \verb;}; \\
  485. \verb;\Endcases;
  486. \end{verse}
  487.  
  488. The \cs\Otherwise\ field is optional.  This construction follows a
  489. general pattern that is common in \Vdm\ input:  lists of things are
  490. separated by \cs\\s, and subfields are separated by \verb;&;s or
  491. \verb;:;s. 
  492. \begin{dangerous}
  493. In reality, there is another, optional argument, after the
  494. \cs\Endcases.  If you were to try typesetting something like
  495. \begin{verbatim}
  496.         (... var = \Cases ...
  497.                    \Endcases)
  498. \end{verbatim}
  499. you'd find the closing right parenthesis in an unexpected place (on
  500. the same line as the $=$, in fact).  To get text to the right of the
  501. \cs\Endcases\ you can place an optional argument within brackets
  502. after it:
  503. \begin{verbatim}
  504.         (... var = \Cases ...
  505.                    \Endcases[)]
  506. \end{verbatim}
  507. Admittedly, this looks a little strange, but it does work.
  508. \end{dangerous}
  509.  
  510. Here is an example of \cs\Cases\ in action:
  511.  
  512. \begin{formula}
  513.   \Cases{ select(x) }
  514.   \nil            & \emptyset \\
  515.   mk-Lst(hd,tl)  & \set{hd} \union elems(tl)
  516.   \Otherwise{ x }
  517.   \Endcases
  518. \end{formula}
  519.  
  520. \begin{verbatim}
  521.      \Cases{ select(x) }
  522.      \nil            & \emptyset \\
  523.      mk-Lst(hd,tl)  & \set{hd} \union elems(tl)
  524.      \Otherwise{ x }
  525.      \Endcases
  526. \end{verbatim}
  527.  
  528. Note the \cs\\ is a {\em separator\/} and not a {\em
  529. terminator\/}---you don't need one after the last item.  Also, the
  530. \cs\Otherwise\ can appear anywhere between the \verb;\Cases{}; and the
  531. \cs\Endcases, but it will always be typeset last.
  532. \begin{dangerous}
  533. Some people prefer the selectors to appear lined up on the left, some
  534. on the right.  If you want them to appear on the left, say
  535. \cs\leftCases; if you want them on the right, say
  536. \cs\rightCases.  The scope of the \cs\leftCases\ and
  537. \cs\rightCases\ commands is the current group.  By default, you
  538. get \cs\rightCases.
  539. \end{dangerous}
  540.  
  541. \subsection*{Other General Points about Formulas}
  542.  
  543. \cs\\ will%
  544. \footnote{For `will' read `should'.} 
  545. {\em always\/}
  546. start a new line.  Sometimes this is done in addition to some other
  547. function (as in the \cs\Cases\ macro, where it delimits a
  548. particular case), but you should be able to use \cs\\ almost
  549. anywhere to force a line break.  Indeed, sooner or later you'll want
  550. to typeset a long formula and \TeX\ will not be able to break the line
  551. sensibly, or will choose an unpleasant break.  In this case you'll
  552. have to use \cs\\.
  553.  
  554. Frequently you need to indent things within multi-line formulas.  To
  555. help you do this, a command is provided which breaks a line, and
  556. indents the next line by an amount which you can supply (in units of
  557. {\tt ems}).  The \cs\T\ command takes a single argument that controls
  558. how much the next line will be indented:
  559.  
  560. \begin{leftside}
  561. \begin{formula}
  562. a \And b \T2
  563. \Implies b \And a \T1
  564. \Or d \And e
  565. \end{formula}
  566. \end{leftside}\begin{rightside}
  567. a \And b \T2
  568. \Implies b \And a \T1
  569. \Or d \And e
  570. \end{verbatim}\end{rightside}
  571.  
  572. The \cs\If, \cs\Let, etc., constructions are all unusual in
  573. that it's impossible to typeset something sensibly to the right of
  574. them.  For example, if you try
  575. \begin{verbatim}
  576.         \exists{x \in S}{
  577.            \If x=0 \Then S=Q \Else S=P \Fi}
  578.         \Or S=\emptyset
  579. \end{verbatim}
  580. then you'll get
  581.  
  582. \begin{vdm}
  583.   \begin{formula}
  584.     \exists{x \in S}{\If x=0 \Then S=Q \Else S=P \Fi} \Or S=\emptyset
  585.   \end{formula}
  586. \end{vdm}
  587.  
  588. \noindent which is unlikely to be what you wanted.
  589.  
  590. You should also remember that where \Vdm\ wants a \mmexp, \TeX\ will
  591. be placed in math mode.  This is usually the right thing to do, but
  592. occasionally you might want a natural language comment to appear
  593. there.
  594. In this case you'll have to insert an \cs\mbox\ or a \cs\parbox\
  595. depending on whether your comment might span one or more lines:
  596.  
  597. \begin{leftside}
  598.   \begin{formula}
  599.     \If \mbox{the condition is true}
  600.     \Then \mbox{do the true part}
  601.     \Else "do the false part"
  602.     \Fi
  603.   \end{formula}
  604. \end{leftside}%
  605. \begin{rightside}
  606. \If \mbox{the condition is true}
  607. \Then \mbox{do the true part}
  608. \Else "do the false part"
  609. \Fi
  610. \end{verbatim}\end{rightside}
  611. The else-part illustrates how quotes can be used an an abbreviation
  612. for \verb;\mbox{...}; within math mode.
  613.  
  614. Finally, all the constructions above will not break at a page
  615. boundary.  This means that you're in big trouble if you want to
  616. typeset a three-page \cs\Cases.  The only statement I can make to
  617. mitigate this is: you shouldn't have expressions that complicated in
  618. the first place---who do you expect to read them?  Remember: ``truth
  619. is beauty'', so if your formulas are not beautiful, then chances are
  620. they're not true either.
  621.  
  622.  
  623.  
  624.  
  625.  
  626. \section*{Typesetting data types}
  627.  
  628. The following table lists the primitive types and values available:
  629.  
  630. \begin{center}
  631. \begin{tabular}{|l|l|l|}
  632. \hline
  633. $\set{0,1,\dots}$    & \Nat        & \cs\Nat     \\
  634. $\set{1,2,\dots}$    & \Natone    & \cs\Natone,\cs\Nati    \\
  635. $\set{\dots,-1,0,1,\dots}$& \Int    & \cs\Int    \\
  636. Real numbers        & \Real        & \cs\Real    \\
  637. $\set{\true,\false}$    & \Bool        & \cs\Bool    \\
  638. Truth            & \true        & \cs\true,\cs\True \\
  639. Falsehood        & \false    & \cs\false,\cs\False\\
  640. Nil            & \nil        & \cs\nil    \\
  641. \hline
  642. \end{tabular}
  643. \end{center}
  644.  
  645. If you need a new keyword, you can create one easily.  For example, if
  646. your favourite brand of logic has ``maybe'' as a value, you can say
  647. \begin{verbatim}
  648.         \makeNewKeyword{\maybe}{maybe}
  649. \end{verbatim}
  650. and henceforth \cs\maybe\ is a valid control sequence that produces
  651. the text \kw{maybe}.  The text of the second argument to
  652. \cs\makeNewKeyword\ can be anything; it doesn't have to match your
  653. control sequence name.
  654. \begin{dangerous}
  655. If you don't like the font that keywords are set in, you can change
  656. them by redefining the command \cs\keywordFontBeginSequence.  By
  657. default it expands to \cs\small\cs\sf.
  658. \end{dangerous}
  659.  
  660. The following type-related commands are provided:
  661.  
  662. \begin{center}
  663. \begin{tabular}{|l|l|l|}
  664. \hline
  665. Output        & Input            & \\
  666. \hline
  667. $\setof{x}$    & \verb;\setof{x};    & set type constructor \\
  668. $\set{a,b,c}$    & \verb;\set{a,b,c};    & set enumeration \\
  669. $\emptyset$    & \cs\emptyset        & the empty set \\
  670. $\seqof{x}$    & \verb;\seqof{x};    & seq. type constructor\\
  671. $\seq{a,b,a,c}$    & \verb;\seq{a,b,a,c};    & seq. enumeration\\
  672. $\emptyseq$    & \cs\emptyseq    & the empty sequence \\
  673. $\mapof{x}{y}$    & \verb;\mapof{x}{y};    & map type constructor \\
  674. $\mapinto{x}{y}$& \verb;\mapinto{x}{y};    & one-one map type \\
  675. $\map{p\mapsto x}$
  676.         & \verb;\map{p\mapsto x}; & map enumeration\\
  677. $\emptymap$    & \cs\emptymap    & the empty map \\
  678. \hline
  679. \end{tabular}
  680. \end{center}
  681.  
  682. \noindent Here are the relevant operators:
  683.  
  684. \begin{center}\small
  685. \begin{tabular}{llllll}
  686. $\in$        & \cs\in    &
  687.     $\owr$    & \cs\owr    &
  688.         $\sconc$    & \cs\sconc    \\
  689. $\notin$    & \cs\notin    &
  690.     $\dres$    & \cs\dres    &
  691.         $\len{l}$    & \verb;\len{l};\\
  692. $\subset$    & \cs\subset&
  693.     $\rres$    & \cs\rres    &
  694.         $\hd{l}$    & \verb;\hd{l};    \\
  695. $\subseteq$    & \cs\subseteq&
  696.     $\dsub$    & \cs\dsub    &
  697.         $\tl{l}$    & \verb;\tl{l};    \\
  698. $\inter$    & \cs\inter,\cs\intersection;&
  699.     $\rsub$    & \cs\rsub    &
  700.         $\elems{l}$    & \verb;\elems{l};\\
  701. $\Inter$    & \cs\Inter,\cs\Intersection;&
  702.     $\dom{m}$&\verb;\dom{m};&
  703.         $\inds{l}$    & \verb;\inds{l};\\
  704. $\union$    & \cs\union    &
  705.     $\rng{m}$&\verb;\rng{m};&
  706.                 &        \\
  707. $\Union$    & \cs\Union    &
  708.     $\Min{s}$& \verb;\Min{s};&
  709.                 &    \\
  710. $\diff$        & \cs\diff,\cs\difference;&
  711.     $\Max{s}$& \verb;\Max{s};&    
  712.                 &    \\
  713. $\card{s}$    & \verb;\card{s};&
  714.         &        &
  715.                 &
  716. \end{tabular}
  717. \end{center}
  718.  
  719. \noindent
  720. (\inds{} and \elems{} are not, strictly speaking, part of VDM any
  721. more; use \dom{} and \rng{}.)
  722.  
  723. \begin{dangerous}
  724. If you invent a new monadic keyword operator (like \dom{}, etc.),
  725. then you can have \Vdm\ define for you a control sequence which
  726. switches font, and puts the right spacing in.  For example,
  727. \begin{verbatim}
  728.         \newMonadicOperator{\inv}{inv}
  729. \end{verbatim}
  730. will define the \cs\inv\ control sequence to print
  731. {\keywordFontBeginSequence inv\/}.  Henceforth you can say, e.g.,
  732. \verb;\inv{Foo};.  All such sequences take one argument (they are
  733. monadic, after all).
  734. \end{dangerous}
  735.  
  736. You can define a new type using
  737. \verb;\type{;type-name\verb;}{;type\verb;};:
  738.  
  739. \begin{leftside}
  740.   \type{Complex}{\Real\x \Real}
  741. \end{leftside}%
  742. \begin{rightside}
  743. \type{Complex}{\Real\x \Real}
  744. \end{verbatim}\end{rightside}
  745.  
  746. Composites types can be typeset using the {\tt composite} environment:
  747.  
  748. \begin{leftside}
  749.   \begin{composite}{Datec}
  750.     day:\set{1,\ldots,366}, \\
  751.     year:\set{1583,\ldots,2599}
  752.   \end{composite}
  753. \end{leftside}%
  754. \begin{rightside}
  755. \begin{composite}{Datec}
  756.   day :\set{1,\ldots,366}, \\
  757.   year:\set{1583,\ldots,2599}
  758. \end{composite}
  759. \end{verbatim}\end{rightside}
  760.  
  761. There is also a {\tt composite*} environment (and an equivalent
  762. \cs\scompose\ control sequence) that places the entire composite
  763. type on a single line:
  764.  
  765. \begin{leftside}
  766.   \begin{composite*}{Celsius}
  767.     \Real
  768.   \end{composite*}
  769. \end{leftside}%
  770. \begin{rightside}
  771. \begin{composite*}{Celsius}
  772.   \Real
  773. \end{composite*}
  774. \end{verbatim}\end{rightside}
  775.  
  776. \begin{leftside}
  777.   \scompose{Celsius}{\Real}
  778. \end{leftside}%
  779. \begin{rightside}
  780. \scompose{Celsius}{\Real}
  781. \end{verbatim}\end{rightside}
  782.  
  783. `Records' can be defined using the {\tt record\/} environment:
  784.  
  785. \begin{verse}
  786. \verb;\begin{record}{;record-type-name\verb;}; \\
  787. field-name \verb;:; field-type \cs\\ \\
  788. \dots \\
  789. \verb;\end{record};
  790. \end{verse}
  791. The colons are used as sub-field separators.
  792.  
  793. \begin{leftside}
  794.   \begin{record}{PERSON}
  795.     NM : \seqof{Char} \\
  796.     FEM : \Bool
  797.   \end{record}
  798. \end{leftside}%
  799. \begin{rightside}
  800.     \begin{record}{PERSON}
  801.       NM : \seqof{Char} \\
  802.       FEM : \Bool
  803.     \end{record}
  804. \end{verbatim}\end{rightside}
  805.  
  806. If the definition is short, you may prefer to use a short form:
  807. \begin{verbatim}
  808.         \defrecord{PERSON}{
  809.           NM : \seqof{Char} \\
  810.           FEM : \Bool
  811.         }
  812. \end{verbatim}
  813.  
  814. \begin{dangerous}
  815. Some people prefer the field names to appear lined up on the left, some
  816. on the right.  If you want them to appear on the left, say
  817. \cs\leftRecord; if you want them on the right, say
  818. \cs\rightRecord.  The scope of the \cs\leftRecord\ and
  819. \cs\rightRecord\ commands are the current group.  By default, you
  820. get \cs\rightRecord.
  821. \end{dangerous}
  822.  
  823. Updating fields of composites using the $\mu$-function can be
  824. specified using \cs\chg:
  825.  
  826. \begin{leftside}
  827.   \begin{formula}
  828.     \chg{p}{FEM}{\Not man(q)}
  829.   \end{formula}
  830. \end{leftside}%
  831. \begin{rightside}
  832. \chg{p}{FEM}{\Not man(q)}
  833. \end{verbatim}\end{rightside}
  834.  
  835. Notice that the $\mu$, parentheses, comma and $\mapsto$ were inserted
  836. automatically.
  837.  
  838.  
  839.  
  840. \section*{How to Typeset Functions}
  841.  
  842. Typesetting $\lambda$-expressions is easy:
  843.  
  844. \begin{leftside}
  845.   \begin{formula}
  846.     \LambdaFn{x,y}{x^2+y^2}
  847.   \end{formula}
  848. \end{leftside}%
  849. \begin{rightside}
  850. \LambdaFn{x,y}{x^2+y^2}
  851. \end{verbatim}\end{rightside}
  852.  
  853. As with \cs\forall, \cs\exists\ and \cs\unique,
  854. \cs\LamdbaFn\ has a *-form that places the body of the function
  855. below and to the right:
  856.  
  857. \begin{leftside}
  858.   \begin{formula}
  859.     \LambdaFn*{x,y,z}{
  860.       (x^2+y^2+z^2)^{\frac12}}
  861.   \end{formula}
  862. \end{leftside}%
  863. \begin{rightside}
  864. \LambdaFn*{x,y,z}{
  865.   (x^2+y^2+z^2)^{\frac12}}
  866. \end{verbatim}\end{rightside}
  867.  
  868. There is also a {\tt fn\/} (function) environment for defining named
  869. functions.  It has the following structure:
  870. \begin{verse}
  871. \verb;\begin{fn}{;name-of-function\verb;}{; argument-list \verb;}; \\
  872. \verb;\signature{;signature-of-function\verb;}; \\
  873. \^{optional precondition}\\
  874. \^{optional postcondition}\\
  875.  body of function (a \mmexp) \\
  876. \cs\end{fn}
  877. \end{verse}
  878.  
  879. See the first page for an example.  The \cs\signature\ is optional
  880. and can be placed anywhere within the body---it will always be typeset
  881. before the body.  Useful macros within the \cs\signature\ are:
  882. \cs\x\ and \cs\to, which yield $\x$ and~$\to$.  Note that you can also
  883. enter functions defined implicitly with pre- and post-conditions; see the
  884. next section on how to enter them.
  885.  
  886. All of the material in the section on formulas is relevant within the
  887. body of the function.
  888.  
  889. \sloppy\sloppy
  890. If you frequently intersperse your function definitions with text (and you
  891. should), you can save some typing by using the {\tt vdmfn\/} environment.
  892. \cs\begin\verb;{vdmfn}; \dots \cs\end\verb;{vdmfn}; is equivalent to
  893. \cs\begin\verb;{vdm};\cs\begin\verb;{fn}; \dots
  894. \cs\end\verb;{fn};\cs\end\verb;{vdm};.
  895.  
  896. The {\tt fn} environment also has a *-form that omits inserting
  897. parentheses around the argument list.  For example:
  898.  
  899.  
  900. \begin{leftside}
  901. \begin{fn*}{MP}{\term{p}\rho\sigma}
  902. \ldots
  903. \end{fn*}
  904. \end{leftside}\begin{rightside}
  905. \begin{fn*}{MP}{
  906.   \term{p}\rho\sigma}
  907. ...
  908. \end{fn*}
  909. \end{verbatim}\end{rightside}
  910.  
  911. If you require the $\DEF$ symbol by itself (for example, in a
  912. footnote), then you can get it by saying \cs\DEF.
  913.  
  914. \subsection*{Invariants}
  915.  
  916. To typeset an invariant on a composite object, use the following
  917. structure:
  918.  
  919. \begin{leftside}
  920. \begin{record}{D}
  921.   day : Day \\
  922.   year : Year
  923. \end{record}
  924. \where
  925. \begin{fn}{inv-D}{mk-D(d,y)}
  926.   is-leapyr(y) \Or d \le 365
  927. \end{fn}
  928. \end{leftside}\begin{rightside}
  929. \begin{record}{D}
  930.   day : Day \\
  931.   year : Year
  932. \end{record}
  933. \where
  934. \begin{fn}{inv-D}{mk-D(d,y)}
  935.   is-leapyr(y) \Or d \le 365
  936. \end{fn}
  937. \end{verbatim}\end{rightside}
  938.  
  939.  
  940. \section*{How to Typeset Operations}
  941.  
  942. Operations are typeset within the {\tt op\/} environment.
  943. The general structure is:
  944.  
  945. \begin{verse}
  946. \verb;\begin{op}{;\^{name-of-operation}\verb;}; \\
  947. \verb;\args{;\^{list-of-arguments}\verb;}; \\
  948. \verb;\res{;\^{result(s)}\verb;}; \\
  949. \verb;\ext{;\^{list-of-externals}\verb;}; \\
  950. \^{pre-condition} \\
  951. \^{post-condition} \\
  952. \verb;\end{op};
  953. \end{verse}
  954.  
  955. Any of \cs\args, \cs\res, \cs\ext, \^{pre-condition} or
  956. \^{post-condition} may be omitted.  \verb;\begin{vdmop}; is an
  957. abbreviation for \verb;\begin{vdm}\begin{op};;  \verb;\end{vdmop}; is an
  958. abbreviation for \verb;\end{op}\end{vdm};.
  959.  
  960. The \^{name-of-operation} can be any one-line expression; it is
  961. typeset in math mode.
  962.  
  963. The \^{list-of-arguments} is a \mmexp\ that can span multiple lines;
  964. force a newline with \cs\\.  If present it is placed within
  965. parentheses.
  966.  
  967. The \^{result(s)} is also any \mmexp.  It is typeset to the right of
  968. any arguments.
  969.  
  970. The \^{list-of-externals} takes the following form:
  971. \begin{verse}
  972. \verb;\ext{;    \\
  973. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  974.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  975. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  976.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  977. \dots \\
  978. \verb;};
  979. \end{verse}
  980. Alternatively, if the list of externals is long (say, more than five
  981. lines) the {\tt externals\/} environmment can be used:
  982. \begin{verse}
  983. \verb;\begin{externals};    \\
  984. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  985.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  986. \quad $\langle$optional \cs\Rd\ or \cs\Wr$\rangle$
  987.     \^{external-name(s)} {\tt :\/} \^{external-types} \cs\\ \\
  988. \dots \\
  989. \verb;\end{externals};
  990. \end{verse}
  991. \begin{dangerous}
  992. Some people prefer the externals identifiers to appear lined up on the
  993. left, some on the right.  If you want them to appear on the left, say
  994. \cs\leftExternals; if you want them on the right, say
  995. \cs\rightExternals.  The scope of the \cs\leftExternals\ and
  996. \cs\rightExternals\ commands are the current group.  By default,
  997. you get \cs\leftExternals.
  998. \end{dangerous}
  999.  
  1000.  
  1001. The \^{pre-condition} and \^{post-condition} take similar forms:
  1002. \begin{verse}
  1003. \verb;\pre{;\mmexp\verb;}; \\
  1004. \end{verse}
  1005. or
  1006. \begin{verse}
  1007. \cs\begin{precond} \\
  1008. \mmexp \\
  1009. \verb;\end{precond};
  1010. \end{verse}
  1011. and
  1012. \begin{verse}
  1013. \verb;\post{;\mmexp\verb;}; \\
  1014. \end{verse}
  1015. or
  1016. \begin{verse}
  1017. \verb;\begin{postcond}; \\
  1018. \mmexp \\
  1019. \verb;\end{postcond};
  1020. \end{verse}
  1021. Use the \cs\begin\dots\cs\end\ style if the \mmexp\ is longer
  1022. than a few lines.
  1023. All of the constructs mentioned in the section on formulas can be used
  1024. within pre- and post-conditions.
  1025.  
  1026. \section*{Proofs}
  1027.  
  1028. Here's an example of typesetting proofs in the ``natural deduction''
  1029. style. 
  1030.  
  1031. \begin{proof}
  1032.   \From E@1 \Or E@2     \\
  1033. 1   \From E@1    \\
  1034.     \Infer E@2 \Or E@1    \` $\vee$-I(h1) \\
  1035. 2   \From E@2        \\
  1036.     \Infer E@2 \Or E@1    \` $\vee$-I(h2) \\
  1037.   \Infer E@2 \Or E@1    \` $\vee$-E(h,1,2)\\
  1038. \end{proof}
  1039. \begin{verbatim}
  1040.         \begin{proof}
  1041.             \From E@1 \Or E@2                           \\
  1042.         1       \From E@1                               \\
  1043.                 \Infer E@2 \Or E@1  \by $\vee$-I(h1)    \\
  1044.         2       \From E@2                               \\
  1045.                 \Infer E@2 \Or E@1  \by $\vee$-I(h2)    \\
  1046.             \Infer E@2 \Or E@1      \by $\vee$-E(h,1,2) \\
  1047.         \end{proof}
  1048. \end{verbatim}
  1049.  
  1050. Proofs are embedded within the {\tt proof} environment.  (A proof does
  1051. not have to be within a {\tt vdm} environment.)  Each line of the
  1052. proof ends with \cs\\.  Lines that begin a subproof
  1053. have \cs\From\ after the equation number.  Lines that end a
  1054. subproof have \cs\Infer\ after the equation number.  Other lines
  1055. have \cs\& after the equation number (see next example).  If you
  1056. don't need an equation number, just omit it,  but you must have one of
  1057. either \cs\From, \cs\Infer\ or \cs\& on each proof line.
  1058. If you want to include a justification of a particular proof line at
  1059. the right hand end of the line, type it after a \cs\by.  \cs\by\
  1060. is optional; you needn't include it if you don't need a justification.
  1061.  
  1062. Points worth bearing in mind:
  1063. \begin{itemize}
  1064. \item    You are automatically placed in math mode after the
  1065.     \cs\From, \cs\Infer\ or \cs\&; the math mode ends
  1066.     at the next \cs\by\ or \cs\\.
  1067. \item    You {\em cannot} break a line in the middle simply by using
  1068.     \cs\\ before \cs\by; you must use separate proof lines
  1069.     to split a formula.
  1070. \item    You are within a {\tt tabbing} environment within a proof, so
  1071.     you can use all the usual {\tt tabbing} commands (\cs\=,
  1072.     \cs\>, etc.) to line things up across proof lines.  Note
  1073.     that you will explicitly have to enter math mode again after
  1074.     any of these commands though.
  1075. \end{itemize}
  1076.  
  1077. Here's another example:
  1078.  
  1079. \begin{proof}
  1080.   \From \forall{x\in X}{E(x); s\in X}    \\
  1081. 1 \&    \Not\exi